
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width: 180px;">
                <select name="select_rep" lay-verify="" >
                    <option value="">Select Rep</option>
                    <option value="1">已修复</option>
                    <option value="0">未修复</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="type" lay-verify="title" autocomplete="off" placeholder="Input Type" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="param" lay-verify="title" autocomplete="off" placeholder="Input Param" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="datetime" id="datetime" placeholder="start_time _ end_time" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var tableIn = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('log/apiError')}",
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['exports'],
            id: 'balanceTable',
            cols: [[
                { type: 'checkbox', fixed: 'left'},
                { type: 'numbers'},
                { field: 'type',  align: 'left', title: 'Type',width: 180},
                {field: 'amount', title: '本地金额($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150},
                {field: 'amount_bank', title: '银行金额($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150},
                { field: 'data_param',  align: 'left', title: 'Desc'},
                { field: 'card_num',  align: 'left', title: 'CardNum',
                    templet: function (d) {
                        const card_num = d.card_num;
                        if(card_num != ''){
                            var html = '<a style="color: #0e8df3;" ' +
                                'href="' + "{:url('cards/cardLog')}?card_num=" + card_num + '">' + card_num + '</a>';
                            return html;
                        }else{
                            return '--';
                        }
                    }
                },

                { align: 'left', title: 'is_rep',width: 100,
                    templet: function (d) {
                        const is_rep = d.is_rep;
                        if(is_rep == '1'){
                            return '<font color="green">已修复</font>';
                        }else{
                            return '<font color="red">未修复</font>';
                        }
                    }
                },
                { align: 'center', title: 'Create Time',width:170,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                // { field: 'option', title: 'Action', templet: function (d) {
                //         return '<a class="layui-btn layui-btn-xs SearchDetail" data-id="' + d.id + '">info</a>';
                //     }, align: 'center', width: 80
                // },
                // { field: 'option', title: 'Action', templet: function (d) {
                //         const is_rep    = d.is_rep;
                //         const d_type    = d.type;
                //         if(is_rep == '1'){
                //             return '--';
                //         }else{
                //             if(d_type =='card_tran_exception'
                //                     || d_type =='tran_review_pending'
                //                     || d_type == 'tran_review_clearing_unfind'){
                //                 return '<a class="layui-btn layui-btn-xs editError" data-id="' + d.id + '">Repair</a>';
                //             }else if(d_type =='tran_review_reversal_state'
                //                     || d_type =='tran_review_clearing'
                //                     || d_type == 'tran_review_reversal_expiration'){
                //                 return '<a class="layui-btn layui-btn-xs changeType" data-id="' + d.id + '">ChangeRep</a>';
                //             }
                //         }
                //     }, align: 'center', width: 120,
                // },
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100,500],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //余额编辑
        $(document).on('click', '.SearchDetail', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('log/showDetail')}?type=error_log&id="+ id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: 'Log Detail',
                        area: ['1000px', '600px'], //宽高
                        content: e.datas,
                        btn:['Close']
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });
        table.on('toolbar(balanceTable)', function(obj) {
            const checkStatus = table.checkStatus(obj.config.id);
            const data = checkStatus.data;
            const url  = "{:url('dataRepairAll')}";
            if(data.length >0){
                var id_array = [];
                for(var i=0;i<data.length;i++){
                    if(data[i].is_rep == '0'){
                        id_array.push(data[i].id);
                    }
                }
                if(id_array.length >0){
                    if(id_array.length >20){
                        layer.msg("Only 20 data can be updated at a time.",{time:2000,icon:2});
                        return false;
                    }
                }else{
                    layer.msg("Select at least one " ,{time:2000,icon:2});
                    return false;
                }
                var loading =parent.layer.load(1, {shade: [0.1,'#fff']});
                $.post(url,{id_array:id_array},function(res){
                    parent.layer.close(loading);
                    if(res.code>0){
                        layer.msg(res.msg, {time: 1500, icon: 1}, function () {
                            layui.table.reload('balanceTable', {
                                where: data.field
                                , page: {
                                    curr: 1 //重新从第 1 页开始
                                }
                            });
                            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                        });
                    }else{
                        layer.msg(res.msg,{time:1500,icon:2});
                    }
                });
            }else{
                layer.msg("Please select the card you want to update.",{time:2000,icon:2});
            }
        })

        //删除
        $(document).on('click', '.editError', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去激活
                var loading =layer.load(1, {shade: [0.1,'#fff']});
                JsPost("{:url('dataRepair')}", { 'id': id}, function (res) {
                    layer.close(loading);
                    if(res.code >0){
                        layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                            tableIn.reload({
                                page:{
                                    curr :1
                                }
                            });
                        });
                    }else{
                        layer.msg(res.msg , {time:1500 , icon:2});
                    }
                });
            }, function () {
                layer.close(1);
            });
        });
        //删除
        $(document).on('click', '.changeType', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去激活
                var loading =layer.load(1, {shade: [0.1,'#fff']});
                JsPost("{:url('changeType')}", { 'id': id}, function (res) {
                    layer.close(loading);
                    if(res.code >0){
                        layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                            tableIn.reload({
                                page:{
                                    curr :1
                                }
                            });
                        });
                    }else{
                        layer.msg(res.msg , {time:1500 , icon:2});
                    }
                });
            }, function () {
                layer.close(1);
            });
        });
    });

</script>